<template>
	<view class="list">
		<view class="list-head">
			<view class="list-head-con">
				<view class="list-head-con-box" v-for="(item,index) in addData" :key="index">
					<view class="head-img">
						<image :src="item.head"></image>
					</view>
					<view class="head-name">
						<text>{{item.nickname}}</text>
					</view>
				</view>
			</view>
			<view class="head-bottom">
				<view class="head-bottom-text">
					<text>选择邀请好友</text>
				</view>
			</view>
		</view>
		<view class="list-content">

			<block v-for="(item,index) in friendData" :key="index">
				<view class="box">
					<view class="con-ridio">
						<radio :checked="item.selected" style="transform: scale(0.9)" class="redio-item"
							@click="redioClickHandler($event,item)">
						</radio>
					</view>
					<view class="con-head">
						<image :src="item.head"></image>
					</view>
					<view class="con-info">
						<view class="con-name">
							<text>{{item.nickname}}</text>
						</view>
						<view class="con-gender">
							<icon-gender-nan v-if="item.gender == 1"></icon-gender-nan>
							<icon-gender-nv v-else></icon-gender-nv>
						</view>
					</view>
				</view>
			</block>
		</view>

	</view>
</template>

<script>
	//引入icon
	import iconGenderNv from '@/components/common/my-icon-gender-nv/my-icon-gender-nv.vue'
	import iconGenderNan from '@/components/common/my-icon-gender-nan/my-icon-gender-nan.vue'

	export default {
		props: ['friendData'],
		components: {
			iconGenderNv,
			iconGenderNan
		},
		data() {
			return {
				addListHead: [],
				addData: []
			}
		},
		methods: {
			redioClickHandler(e, item) {
				for (var i = 0; i < this.friendData.length; i++) {
					if (this.friendData[i].userId == item.userId) {
						this.friendData[i].selected = !this.friendData[i].selected
					}
				}
				//console.log(this.addData.length)
				if (this.addData.length == 0) {
					this.addData.push(item)
				} else {
					//var newData = []
					for (var j = 0; j < this.addData.length; j++) {
						if (this.addData[j].userId == item.userId) {
							this.addData.splice(j, 1)
							this.changeData()
							return
						}
					}
					this.addData.push(item)
				}
				this.changeData()
			},
			changeData() {
				this.$emit('changeData', this.addData)
			}
		},
		created() {
			//数据处理
			if (this.friendData.length == 0) {
				return
			}
			for (var i = 0; i < this.friendData.length; i++) {
				this.friendData[i].selected = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list-head {
		width: 100%;
		// height: 160rpx;
		border-bottom: 3rpx solid rgba(128, 128, 128, 1);

		.list-head-con {
			// height: 120rpx;
			display: flex;
			flex-wrap: wrap;
			width: 90%;
			margin-left: 5%;
			padding: 0 10rpx;

			.list-head-con-box {
				width: 20%;
			}

			view {
				// width: 20%;
				text-align: center;

				image {
					margin-top: 25rpx;
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
				}
			}

			.head-name {
				font-size: 18rpx;
			}
		}

		.head-bottom {
			color: rgba(128, 128, 128, 1);
			font-size: 26rpx;
			font-weight: 500;

			view {
				text-align: center;
			}
		}
	}

	.box {
		display: flex;
		width: 90%;
		margin-left: 5%;
		height: 120rpx;
	}

	.con-ridio {
		.redio-item {
			line-height: 120rpx;
		}
	}

	.con-head {
		image {
			width: 90rpx;
			height: 90rpx;
			border-radius: 50%;
			margin-top: 15rpx;
		}
	}

	.con-info {
		margin-top: 10rpx;
		margin-left: 30rpx;

		.con-name {
			margin-bottom: 10rpx;

			text {
				font-size: 32rpx;
			}
		}
	}
</style>